import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class TuplePerson implements WritableComparable<TuplePerson> {
    private String Person0;
    private String Person1;

    public TuplePerson() {
    }

    public TuplePerson(String Person0, String Person1) {
        set(Person0, Person1);
    }

    public void set(TuplePerson key) {
        this.set(key.Person0, key.Person1);
    }

    public void set(String Person0, String Person1) {
        if (Person0.compareTo(Person1) < 0) {
            this.Person0 = Person0;
            this.Person1 = Person1;
        } else {
            this.Person0 = Person1;
            this.Person1 = Person0;
        }
    }

    @Override
    public String toString() {
        return "[" + Person0 + "," + Person1 + "]";
    }

    @Override
    public int compareTo(TuplePerson o) {
        if (this.Person0.compareTo(o.Person0) < 0) return -1;
        else if (this.Person0.compareTo(o.Person0) > 0) return 1;
        else return this.Person1.compareTo(o.Person1);
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(Person0);
        dataOutput.writeUTF(Person1);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        Person0 = dataInput.readUTF();
        Person1 = dataInput.readUTF();
    }
}
